Search this book | Previous | Table of contents | Next

WWW Scripting


This chapter outlines and demonstrates the fundamental concepts behind common gateway interface (CGI) scripting with MacHTTP and AppleScript.

The real potential of Web servers lies in their ability to run programs behind the scenes and return the results of these programs to the reader. This is known as common gateway interface (CGI) scripting. Basic CGI scripts include the ability to display the current time or the number of users who have accessed a server. More advanced and useful CGI scripts allow readers to search databases, complete survey forms and have them sent to an email address, implement imagemaps, or take pictures of remote places and have the pictures returned.

CGI scripts are made available to a Web browser through the use of simple links, specialized URLs containing a question marks (?), ISINDEX HTML tags, or HTML+ FORMs. After the user completes an HTML document containing one of these elements, a query is passed to the Web server, which is passed on to the CGI script itself. The script processes the input, formats the output into HTTP codes and/or an HTML document, and returns these items back to the WWW server. The server then passes it along to the client application.

CGI scripts can be written in almost any language. Common languages include C, Perl (MacPerl), AppleScript, Frontier (Aretha), or even HyperCard's HyperTalk. The limitation of the scripting language you choose is that it must be able to receive AppleEvents because AppleEvents are the technology by which MacHTTP communicates with the CGI program.

This chapter outlines how to write CGI scripts using AppleScript. This is because AppleScript is distributed with MacHTTP and it is the most widely supported Macintosh-based scripting language next to HyperTalk. This chapter does not discuss how to write AppleScripts in general since such a topic is beyond the scope of this book; CGI scripting is a specialized form of AppleScripting. Consequently, you are expected to have at least some AppleScripting experience.

If you do not have any experience writing AppleScripts, then please consult some of the texts and Internet resources found in the See Also section of this chapter.

The use of HyperTalk, Frontier, nor MacPerl are discussed in this chapter. HyperCard's HyperTalk is seen as relatively slow when it comes to other programming languages, and its overhead in terms of RAM, when compared to other languages, is high. This is true of MacPerl as well, although MacPerl has the slight advantage of being a cross-platform application since many operating systems support the perl programming language. Frontier (or Aretha as it is now being called), is a more robust scripting language when compared to AppleScript but its syntax is more like traditional programming. Furthermore, because of its internal data structure, it is more difficult to demonstrate CGI fundamentals without knowing a lot about Aretha itself.

  1. "Hello, World!"
  2. Making your scripts HTTP-friendly
  3. Global variables in .script scripts
  4. Adding rudimentary input to your .script files
  5. Getting input via <ISINDEX>
  6. But don't use .script files
  7. Running scripts via AppleEvents
  8. Global variables and ISINDEX revisited
  9. Trapping and handling errors
  10. Overriding the "Stay Open" option
  11. Using FORMs to get input
  12. Decoding and reading the input in your scripts

See Also

  1. "AppleScript Archives" <URL:ftp://gaea.kgs.ukans.edu/applescript/>

  2. "Overview of CGI" - "This page contains pointers to information and resources on the Common Gateway Interface, a standard for the interface between external gateway programs and information servers." <URL:http://www.w3.org/hypertext/WWW/CGI/Overview.html>

  3. "Common Gateway Interface" - [This is the official specification for CGI scripting.] <URL:http://hoohoo.ncsa.uiuc.edu/cgi/intro.html>

  4. Chuck Shotton, "Using FileMaker Pro with MacHTTP" - An archive with sample forms and CGI that shows how to hook MacHTTP to FMPro. <URL:http://www.biap.com/machttp/examples/fmpro.sit.hqx>

  5. Chuck Shotton, "HyperCard CGI Demo" - Sample stack and HTML form demonstrating how HyperCard can be used to process searches, forms, etc. using the new CGI file type and "sdoc" AppleEvent sent by MacHTTP. <URL:http://www.biap.com/machttp/ftp/hc_cgi_demo.sit.hqx>

  6. Chuck Shotton, "Writing Search Engines for MacHTTP " - This points to an archive containing C source code for a sample application that performs searches in conjunction with MacHTTP using the "srch" AppleEvent. <URL:http://www.biap.com/machttp/ftp/search_ex.sit.hqx>

  7. Daaron Dwyer, "CGIs In Mac C" <URL:http://www.mccom.com/CGIinC/>

  8. Danny Goodman, Complete AppleScript Handbook (Random House: New York, 1994)

  9. Dave Winer, "Aretha Website" - "Frontier is a scripting system for the Macintosh. Lots of features, lots of verbs. It used to be a commercial product, but now it's free. Why? Because I want Frontier to have a shot at becoming a standard. I think it'll be fun!" <URL:http://www.hotwired.com/staff/userland/aretha/>

  10. Derrick Schneider, Tao of AppleScript (Hayden Books: Carmel, IN, 1993)

  11. Grant Neufeld, "Grant's CGI Framework" - Grant's CGI Framework is a framework for writing 68K Macintosh CGI applications in C. It currently comes with a CodeWarrior project. Features: - AppleScriptable (including the CGI sdoc event!) - Threaded - Single function entry-point for customizing to your own needs - If you use it to write free applications, it's free to use <URL:http://arpp1.carleton.ca/grant/mac/grantscgi.html>

  12. Ian Andrew Bell, "Macintosh WWW Tools Compendium" <URL:http://www.arpp.sfu.ca/tools/>

  13. John O'Fallon, "Maxum Home Page" - [This page documents many of the products of Maxum.] <URL:HTTP://www.digimark.net/maxum/>

  14. Jon Wiederspan, "Extending WebSTAR" - Below are links to pages that hopefully will help you learn how to create CGI applications to extend the capabilities of your WebSTAR server. The primary requirements for following these lessons are a willingness to learn, patience with my jokes, and a WebSTAR server to practice on. Since the language I use in these lessons is AppleScript, it would also be a good idea to have some familiarity with it, although many complete beginners find the information here sufficient to get going. <URL:http://www.uwtc.washington.edu/Computing/WWW/Lessons/START_HERE.html>

  15. Jon Wiederspan, "Extending MacHTTP" - The following is a directory of the pages I have or hope to have soon that will help you learn how to use and/or create CGI applications to extend the capabilities of your MacHTTP server. The only requirement for following these lessons is a willingness to learn, patience with my jokes, and a MacHTTP server to practice on. <URL:http://www.biap.com/tutorials/Extending_MacHTTP/ExtendingMacHTTP.html>

  16. Jon Wiederspan, "MacWWW - CGI Applications" - [This page lists various CGI applications for use with your Macintosh-based WWW server.] <URL:http://www.uwtc.washington.edu/Computing/WWW/Mac/CGI.html>

  17. Jon Wiederspan, "Extending MacHTTP" <URL:http://www.uwtc.washington.edu/Computing/WWW/ExtendingMacHTTP.html>

  18. Martin Fenner, Fred Terry, and PreFab Software, Inc., "ScriptWeb" - "This virtual site is a collaborative effort to provide a single source of information for Macintosh scripting, primarily for AppleScript and Frontier." <URL:http://www.gz.com/scriptweb/>

  19. Mason Hale, "Frontier CGI Scripting" - This is the home of documentation and examples related to the writing and running of CGI scripts in the Frontier scripting environment. <URL:http://www.webedge.com/frontier/>

  20. Matthias Neeracher, "MacPerl Q & A" <URL:http://err.ethz.ch/members/neeri/macintosh/perl-qa.html>

  21. Netscape Communications, Inc., "Netscape API for the Macintosh" - "Netscape uses AppleEvents to interact with other Macintosh applications. It is scriptable, and partially recordable. Most of the events (and all Netscape-specific ones) are documented in the Netscape's AppleEvent dictionary. You see the dictionary with the Script Editor, a scripting utility available from Apple." <URL:http://home.netscape.com/newsref/std/mac-remote-control.html>

  22. Robert Godwin-Jones, "Guide to Web Forms and CGI Scripts for Language Learning" <URL:http://www.fln.vcu.edu/cgi/interact.html>

  23. Sandra Silcot, "MacPerl Primer" - "This Primer is intended to assist new users get started with Macintosh Perl, and to point out salient differences for experienced Unix Perlers. This Primer is not a language reference manual, nor does it replace Matthias's documentation or Hal Wine's Frequently Asked Questions (FAQ) about MacPerl. The primer assumes you have already obtained and installed MacPerl, and that you have read the MacPerl FAQ." <URL:http://www.unimelb.edu.au/~ssilcot/macperl-primer/home.html>

  24. Scott S. Lawton, "Scripting" - Our goal is to make this site one of the three most useful places on the Web for Macintosh script writers, focusing on AppleScript and Frontier. (We also don't mind some good -- hopefully friendly -- competition!) <URL:http://www.tiac.net/prefab/scripting.html>

  25. Spyglass, Inc. , "Software Development Interface" - "This document describes a cross-platform API which can be used to extend the capabilities of Web browsers by integrating them with other applications. The API is specified as a set of platform-independent generic verbs which can be issued either to or from Web browsers. Platform-specific implementations of this spec are given for the AppleEvents and DDE transports. Future transports to be provided include OLE2 and TCP/IP (for UNIX)." <URL:http://www.spyglass.com:4040/newtechnology/integration/iapi.htm>

  26. Tom Trinko, Applied Mac Scripting (M and T Books: New York, 1995) - The volume represents just about the only book available describing how to program Frontier.


Search this book | Previous | Table of contents | Next

Eric last edited this page on September 26, 1995. Please feel free to send comments.